import Vue from 'vue'
import VueRouter from 'vue-router'
// import UserInfo from '../components/public/UserInfo.vue'//同步路由加载
import GuidePage from '../components/public/GuidePage.vue'//同步路由加载
Vue.use(VueRouter)

const routes = [
  {
    path: "/guidePage",
    name: 'GuidePage',
    component:GuidePage
  },
  {
    path: "/userInfo",
    name: 'UserInfo',
    component:()=>import('../components/public/UserInfo.vue'),
    // 独享守卫
    beforeEnter:(to,from,next)=>{
      let login=window.localStorage.getItem("login");
      //若没登录
      if(!login) {
        next('/login');
        return;
      }else{
        next();
      }
    }
  },
  {
    path: '/',
    name: 'Main',
    component:  ()=>import('../views/Main.vue'),    
    children:[    
      {
        path: 'home',
        name: 'Home',
        //别名指向home
        alias:'',
        component: ()=>import('../views/Home.vue')
      },
      {
        path: 'listen', //听歌
        name: 'Listen',
        component:()=>import('../views/Listen.vue')
      },
      {
        path: 'searchs', //搜索
        name: 'Searchs',
        component:()=>import('../views/Searchs.vue')
      },
      {
        path: 'mv',
        name: 'Mv',
        component:()=>import('../views/Mv.vue')
      }
    ]

  },
  {
    path: '/player', //播放音乐控件
    name: 'Player',
    component: ()=>import('../components/public/Player.vue')
  },
  {
    path: '/fullLayout', //播放音乐控件
    name: 'FullLayout',
    component: ()=>import('../components/public/FullLayout.vue')
  },
  {
    path: '/rankList', // 歌单歌曲列表
    name: 'RankList',
    component:()=>import('../components/search/RankList.vue')
  },
  {
    path: '/searchMusic', //首页搜索音乐
    name: 'SearchMusic',
    component:()=>import('../components/public/SearchMusic.vue')
  },
  {
    path: '/highMusic', // 精品歌单歌曲列表
    name: 'HighMusic',
    component:()=>import('../components/search/HighMusic.vue')
  },
  {
    path: '/songMenu', // home歌单歌曲列表
    name: 'SongMenu',
    component:()=>import('../components/home/SongMenu.vue')
  },
  {
    path: '/login', //登录
    name: 'Login',
    component: ()=>import('../components/public/Login.vue')
  },
  {
    path: '/register', //注册
    name: 'Register',
    component: ()=>import('../components/public/Register.vue')
  },
  {
    path: '/singerList', // listen歌手列表
    name: 'SingerList',
    component:()=>import('../components/listen/SingerList.vue')
  },
  {
    path: '/homemv', // home播放mv
    name: 'HomeMv',
    component:()=>import('../components/home/HomeMv.vue')
  },
  
]

const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})

// router.beforeEach((to,from,next)=>{
//   let login =window.localStorage.getItem("login");
//   //登录界面
//   if(to.path=="/login") {
//     next();
//     return;
//   }else{
//     //若没登录
//     if(!login) {
//       //进入登录页面
//       next("/login");
//       return;
//     }else{
//       next();
//     }
//   }
// })

export default router
